package openase.audiosearch.processor;

import openase.audiosearch.comm.request.AudioRegistration;
import openase.audiosearch.comm.request.AudioSearch;
import openase.audiosearch.comm.request.Request;
import openase.audiosearch.comm.response.ExecutionError;
import openase.audiosearch.comm.response.Response;
import openase.audiosearch.comm.response.UnknownRequest;

public abstract class RequestProcessorFacade {

	public static Response process(Request request) {
		if (request == null) {
			return new UnknownRequest();
		}

		try {
			if (request instanceof AudioRegistration) {
				return AudioRegistrationRequestProcessor.process((AudioRegistration) request);
			}
			if (request instanceof AudioSearch) {
				return AudioSearchRequestProcessor.process((AudioSearch) request);
			}
			return new UnknownRequest();
		} catch (Throwable t) {
			return new ExecutionError(t.getMessage());
		}
	}
}
